using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the Category2 class.
	/// </summary>
    [Serializable]
	public partial class Category2Collection : ActiveList<Category2, Category2Collection>
	{	   
		public Category2Collection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>Category2Collection</returns>
		public Category2Collection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Category2 o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Category2 table.
	/// </summary>
	[Serializable]
	public partial class Category2 : ActiveRecord<Category2>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Category2()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Category2(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Category2(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Category2(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Category2", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCategoryID = new TableSchema.TableColumn(schema);
				colvarCategoryID.ColumnName = "CategoryID";
				colvarCategoryID.DataType = DbType.Int32;
				colvarCategoryID.MaxLength = 0;
				colvarCategoryID.AutoIncrement = true;
				colvarCategoryID.IsNullable = false;
				colvarCategoryID.IsPrimaryKey = true;
				colvarCategoryID.IsForeignKey = false;
				colvarCategoryID.IsReadOnly = false;
				colvarCategoryID.DefaultSetting = @"";
				colvarCategoryID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryID);
				
				TableSchema.TableColumn colvarCategoryCode = new TableSchema.TableColumn(schema);
				colvarCategoryCode.ColumnName = "CategoryCode";
				colvarCategoryCode.DataType = DbType.Int32;
				colvarCategoryCode.MaxLength = 0;
				colvarCategoryCode.AutoIncrement = false;
				colvarCategoryCode.IsNullable = false;
				colvarCategoryCode.IsPrimaryKey = false;
				colvarCategoryCode.IsForeignKey = false;
				colvarCategoryCode.IsReadOnly = false;
				colvarCategoryCode.DefaultSetting = @"";
				colvarCategoryCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryCode);
				
				TableSchema.TableColumn colvarCategoryName = new TableSchema.TableColumn(schema);
				colvarCategoryName.ColumnName = "CategoryName";
				colvarCategoryName.DataType = DbType.AnsiString;
				colvarCategoryName.MaxLength = 255;
				colvarCategoryName.AutoIncrement = false;
				colvarCategoryName.IsNullable = true;
				colvarCategoryName.IsPrimaryKey = false;
				colvarCategoryName.IsForeignKey = false;
				colvarCategoryName.IsReadOnly = false;
				colvarCategoryName.DefaultSetting = @"";
				colvarCategoryName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryName);
				
				TableSchema.TableColumn colvarSubSectorCode = new TableSchema.TableColumn(schema);
				colvarSubSectorCode.ColumnName = "SubSectorCode";
				colvarSubSectorCode.DataType = DbType.Int32;
				colvarSubSectorCode.MaxLength = 0;
				colvarSubSectorCode.AutoIncrement = false;
				colvarSubSectorCode.IsNullable = true;
				colvarSubSectorCode.IsPrimaryKey = false;
				colvarSubSectorCode.IsForeignKey = false;
				colvarSubSectorCode.IsReadOnly = false;
				colvarSubSectorCode.DefaultSetting = @"";
				colvarSubSectorCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSubSectorCode);
				
				TableSchema.TableColumn colvarMediaType = new TableSchema.TableColumn(schema);
				colvarMediaType.ColumnName = "MediaType";
				colvarMediaType.DataType = DbType.AnsiString;
				colvarMediaType.MaxLength = 5;
				colvarMediaType.AutoIncrement = false;
				colvarMediaType.IsNullable = true;
				colvarMediaType.IsPrimaryKey = false;
				colvarMediaType.IsForeignKey = false;
				colvarMediaType.IsReadOnly = false;
				colvarMediaType.DefaultSetting = @"";
				colvarMediaType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaType);
				
				TableSchema.TableColumn colvarTv = new TableSchema.TableColumn(schema);
				colvarTv.ColumnName = "TV";
				colvarTv.DataType = DbType.Boolean;
				colvarTv.MaxLength = 0;
				colvarTv.AutoIncrement = false;
				colvarTv.IsNullable = true;
				colvarTv.IsPrimaryKey = false;
				colvarTv.IsForeignKey = false;
				colvarTv.IsReadOnly = false;
				colvarTv.DefaultSetting = @"";
				colvarTv.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTv);
				
				TableSchema.TableColumn colvarRd = new TableSchema.TableColumn(schema);
				colvarRd.ColumnName = "RD";
				colvarRd.DataType = DbType.Boolean;
				colvarRd.MaxLength = 0;
				colvarRd.AutoIncrement = false;
				colvarRd.IsNullable = true;
				colvarRd.IsPrimaryKey = false;
				colvarRd.IsForeignKey = false;
				colvarRd.IsReadOnly = false;
				colvarRd.DefaultSetting = @"";
				colvarRd.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRd);
				
				TableSchema.TableColumn colvarCb = new TableSchema.TableColumn(schema);
				colvarCb.ColumnName = "CB";
				colvarCb.DataType = DbType.Boolean;
				colvarCb.MaxLength = 0;
				colvarCb.AutoIncrement = false;
				colvarCb.IsNullable = true;
				colvarCb.IsPrimaryKey = false;
				colvarCb.IsForeignKey = false;
				colvarCb.IsReadOnly = false;
				colvarCb.DefaultSetting = @"";
				colvarCb.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCb);
				
				TableSchema.TableColumn colvarPr = new TableSchema.TableColumn(schema);
				colvarPr.ColumnName = "PR";
				colvarPr.DataType = DbType.Boolean;
				colvarPr.MaxLength = 0;
				colvarPr.AutoIncrement = false;
				colvarPr.IsNullable = true;
				colvarPr.IsPrimaryKey = false;
				colvarPr.IsForeignKey = false;
				colvarPr.IsReadOnly = false;
				colvarPr.DefaultSetting = @"";
				colvarPr.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPr);
				
				TableSchema.TableColumn colvarOd = new TableSchema.TableColumn(schema);
				colvarOd.ColumnName = "OD";
				colvarOd.DataType = DbType.Boolean;
				colvarOd.MaxLength = 0;
				colvarOd.AutoIncrement = false;
				colvarOd.IsNullable = true;
				colvarOd.IsPrimaryKey = false;
				colvarOd.IsForeignKey = false;
				colvarOd.IsReadOnly = false;
				colvarOd.DefaultSetting = @"";
				colvarOd.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOd);
				
				TableSchema.TableColumn colvarNs = new TableSchema.TableColumn(schema);
				colvarNs.ColumnName = "NS";
				colvarNs.DataType = DbType.Boolean;
				colvarNs.MaxLength = 0;
				colvarNs.AutoIncrement = false;
				colvarNs.IsNullable = true;
				colvarNs.IsPrimaryKey = false;
				colvarNs.IsForeignKey = false;
				colvarNs.IsReadOnly = false;
				colvarNs.DefaultSetting = @"";
				colvarNs.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNs);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				colvarDateAdded.DefaultSetting = @"";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				colvarDateModified.DefaultSetting = @"";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				TableSchema.TableColumn colvarInX = new TableSchema.TableColumn(schema);
				colvarInX.ColumnName = "IN";
				colvarInX.DataType = DbType.Boolean;
				colvarInX.MaxLength = 0;
				colvarInX.AutoIncrement = false;
				colvarInX.IsNullable = true;
				colvarInX.IsPrimaryKey = false;
				colvarInX.IsForeignKey = false;
				colvarInX.IsReadOnly = false;
				colvarInX.DefaultSetting = @"";
				colvarInX.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInX);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("Category2",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("CategoryID")]
		[Bindable(true)]
		public int CategoryID 
		{
			get { return GetColumnValue<int>(Columns.CategoryID); }
			set { SetColumnValue(Columns.CategoryID, value); }
		}
		  
		[XmlAttribute("CategoryCode")]
		[Bindable(true)]
		public int CategoryCode 
		{
			get { return GetColumnValue<int>(Columns.CategoryCode); }
			set { SetColumnValue(Columns.CategoryCode, value); }
		}
		  
		[XmlAttribute("CategoryName")]
		[Bindable(true)]
		public string CategoryName 
		{
			get { return GetColumnValue<string>(Columns.CategoryName); }
			set { SetColumnValue(Columns.CategoryName, value); }
		}
		  
		[XmlAttribute("SubSectorCode")]
		[Bindable(true)]
		public int? SubSectorCode 
		{
			get { return GetColumnValue<int?>(Columns.SubSectorCode); }
			set { SetColumnValue(Columns.SubSectorCode, value); }
		}
		  
		[XmlAttribute("MediaType")]
		[Bindable(true)]
		public string MediaType 
		{
			get { return GetColumnValue<string>(Columns.MediaType); }
			set { SetColumnValue(Columns.MediaType, value); }
		}
		  
		[XmlAttribute("Tv")]
		[Bindable(true)]
		public bool? Tv 
		{
			get { return GetColumnValue<bool?>(Columns.Tv); }
			set { SetColumnValue(Columns.Tv, value); }
		}
		  
		[XmlAttribute("Rd")]
		[Bindable(true)]
		public bool? Rd 
		{
			get { return GetColumnValue<bool?>(Columns.Rd); }
			set { SetColumnValue(Columns.Rd, value); }
		}
		  
		[XmlAttribute("Cb")]
		[Bindable(true)]
		public bool? Cb 
		{
			get { return GetColumnValue<bool?>(Columns.Cb); }
			set { SetColumnValue(Columns.Cb, value); }
		}
		  
		[XmlAttribute("Pr")]
		[Bindable(true)]
		public bool? Pr 
		{
			get { return GetColumnValue<bool?>(Columns.Pr); }
			set { SetColumnValue(Columns.Pr, value); }
		}
		  
		[XmlAttribute("Od")]
		[Bindable(true)]
		public bool? Od 
		{
			get { return GetColumnValue<bool?>(Columns.Od); }
			set { SetColumnValue(Columns.Od, value); }
		}
		  
		[XmlAttribute("Ns")]
		[Bindable(true)]
		public bool? Ns 
		{
			get { return GetColumnValue<bool?>(Columns.Ns); }
			set { SetColumnValue(Columns.Ns, value); }
		}
		  
		[XmlAttribute("DateAdded")]
		[Bindable(true)]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>(Columns.DateAdded); }
			set { SetColumnValue(Columns.DateAdded, value); }
		}
		  
		[XmlAttribute("DateModified")]
		[Bindable(true)]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>(Columns.DateModified); }
			set { SetColumnValue(Columns.DateModified, value); }
		}
		  
		[XmlAttribute("InX")]
		[Bindable(true)]
		public bool? InX 
		{
			get { return GetColumnValue<bool?>(Columns.InX); }
			set { SetColumnValue(Columns.InX, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varCategoryCode,string varCategoryName,int? varSubSectorCode,string varMediaType,bool? varTv,bool? varRd,bool? varCb,bool? varPr,bool? varOd,bool? varNs,DateTime varDateAdded,DateTime varDateModified,bool? varInX)
		{
			Category2 item = new Category2();
			
			item.CategoryCode = varCategoryCode;
			
			item.CategoryName = varCategoryName;
			
			item.SubSectorCode = varSubSectorCode;
			
			item.MediaType = varMediaType;
			
			item.Tv = varTv;
			
			item.Rd = varRd;
			
			item.Cb = varCb;
			
			item.Pr = varPr;
			
			item.Od = varOd;
			
			item.Ns = varNs;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
			item.InX = varInX;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varCategoryID,int varCategoryCode,string varCategoryName,int? varSubSectorCode,string varMediaType,bool? varTv,bool? varRd,bool? varCb,bool? varPr,bool? varOd,bool? varNs,DateTime varDateAdded,DateTime varDateModified,bool? varInX)
		{
			Category2 item = new Category2();
			
				item.CategoryID = varCategoryID;
			
				item.CategoryCode = varCategoryCode;
			
				item.CategoryName = varCategoryName;
			
				item.SubSectorCode = varSubSectorCode;
			
				item.MediaType = varMediaType;
			
				item.Tv = varTv;
			
				item.Rd = varRd;
			
				item.Cb = varCb;
			
				item.Pr = varPr;
			
				item.Od = varOd;
			
				item.Ns = varNs;
			
				item.DateAdded = varDateAdded;
			
				item.DateModified = varDateModified;
			
				item.InX = varInX;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn CategoryIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn CategoryCodeColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn CategoryNameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn SubSectorCodeColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn MediaTypeColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn TvColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn RdColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn CbColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn PrColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn OdColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn NsColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn DateAddedColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        public static TableSchema.TableColumn DateModifiedColumn
        {
            get { return Schema.Columns[12]; }
        }
        
        
        
        public static TableSchema.TableColumn InXColumn
        {
            get { return Schema.Columns[13]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CategoryID = @"CategoryID";
			 public static string CategoryCode = @"CategoryCode";
			 public static string CategoryName = @"CategoryName";
			 public static string SubSectorCode = @"SubSectorCode";
			 public static string MediaType = @"MediaType";
			 public static string Tv = @"TV";
			 public static string Rd = @"RD";
			 public static string Cb = @"CB";
			 public static string Pr = @"PR";
			 public static string Od = @"OD";
			 public static string Ns = @"NS";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
			 public static string InX = @"IN";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
